package com.xin.beauty.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xin.beauty.mapper.ProjectMapper;
import com.xin.beauty.pojo.entity.Project;
import com.xin.beauty.pojo.vo.ProjectExcelVO;
import org.springframework.beans.BeanUtils;

public class ProjectExcelListener extends AnalysisEventListener<ProjectExcelVO> {
    private ProjectMapper projectMapper;

    public ProjectExcelListener(ProjectMapper projectMapper) {
        this.projectMapper = projectMapper;
    }

    //一行一行读取excle中的内容，从第二行开始读取
    @Override
    public void invoke(ProjectExcelVO projectExcelVO, AnalysisContext analysisContext) {
        System.out.println("ProjectExcelListener.invoke");
        Project project = new Project();
        BeanUtils.copyProperties(projectExcelVO, project);
        //插入的数据避免和原有id冲突
        project.setId(null);
        projectMapper.insert(project);
    }

    //读取之后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("ProjectExcelListener.doAfterAllAnalysed");
    }
}
